/*
 * libosso.vapi
 *
 * Copyright (C) 2007 Instituto Nokia de Tecnologia
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 *     Marcelo Lira dos Santos <setanta@gmail.com>
 */

[CCode (cheader_filename = "libosso.h")]
namespace Osso {

    [CCode (ref_function = "osso_initialize",
            unref_function = "osso_deinitialize", cname = "osso_context_t",
            cprefix = "osso_", cheader_filename = "libosso.h")]
    public class Context {
        [CCode (cname = "osso_initialize")]
        public Context (string application, string version, bool activation,
                        GLib.MainContext context);

        /* RPC */
        public Error rpc_run (string service, string object_path, string iface,
                              string method, out Rpc retval, int argument_type,
                              ...);
        //public Error rpc_run_with_argfill (string service, string object_path,
        //                                   string iface, string method,
        //                                   out Rpc retval,
        //                                   ref RpcArgfill argfill,
        //                                   pointer argfill_data);
        public Error rpc_run_system (string service, string object_path,
                                     string iface, string method,
                                     out Rpc retval, int argument_type, ...);
        //public Error rpc_run_system_with_argfill (string service,
        //                                          string object_path,
        //                                          string iface,
        //                                          string method,
        //                                          out Rpc retval,
        //                                          ref RpcArgfill argfill,
        //                                          pointer argfill_data);
        public Error rpc_run_with_defaults (string application, string method,
                                            out Rpc retval, int argument_type,
                                            ...);
        public Error rpc_async_run (string service, string object_path,
                                    string iface, string method,
                                    ref RpcAsync async_callback, pointer data,
                                    int argument_type, ...);
        //public Error rpc_async_run_with_argfill (string service,
        //                                         string object_path,
        //                                         string iface, string method,
        //                                         ref RpcAsync async_callback,
        //                                         pointer data,
        //                                         ref RpcArgfill argfill,
        //                                         pointer argfill_data);
        public Error rpc_async_run_with_defaults (string application,
                                                  string method,
                                                  ref RpcAsync async_callback,
                                                  pointer data,
                                                  int argument_type, ...);
        //[CCode (cname = "osso_rpc_set_cb_f_with_free")]
        //public Error set_rpc_callback_with_free (string service,
        //                                         string object_path,
        //                                         string iface,
        //                                         ref RpcCallback cb,
        //                                         pointer data,
        //                                         osso_rpc_retval_free_f *retval_free);
        [CCode (cname = "osso_rpc_set_cb_f")]
        public Error set_rpc_callback (string service, string object_path,
                                       string iface, ref RpcCallback cb,
                                       pointer data);
        //[CCode (cname = "osso_rpc_set_default_cb_f_with_free")]
        //public Error set_rpc_default_callback_with_free (string service,
        //                                                 string object_path,
        //                                                 string iface,
        //                                                 ref RpcCallback cb,
        //                                                 pointer data,
        //                                                 osso_rpc_retval_free_f *retval_free);
        [CCode (cname = "osso_rpc_set_default_cb_f")]
        public Error set_rpc_default_callback (RpcCallback cb, pointer data);
        [CCode (cname = "osso_rpc_unset_cb_f")]
        public Error unset_rpc_callback (string service, string object_path,
                                         string iface, ref RpcCallback cb,
                                         pointer data);
        [CCode (cname = "osso_rpc_unset_default_cb_f")]
        public Error unset_rpc_default_callback (ref RpcCallback cb,
                                                 pointer data);
        [CCode (cname = "osso_rpc_get_timeout")]
        public Error get_rpc_timeout (ref int timeout);
        [CCode (cname = "osso_rpc_set_timeout")]
        public Error set_rpc_timeout (int timeout);

        /* Application */
        public Error application_top (string application, string arguments);
        [CCode (cname = "osso_application_set_top_callback")]
        public Error set_application_top_callback (ApplicationTopCallback cb,
                                                   pointer data);
        [CCode (cname = "osso_application_unset_top_callback")]
        public Error unset_application_top_callback (ApplicationTopCallback cb,
                                                     pointer data);
        [CCode (cname = "osso_application_set_autosave_callback")]
        public Error set_application_autosave_callback (
                ApplicationAutosaveCallback cb, pointer data);
        [CCode (cname = "osso_application_unset_autosave_callback")]
        public Error unset_application_autosave_callback (
                ApplicationAutosaveCallback cb, pointer data);
        public Error application_userdata_changed ();
        public Error application_autosave_force ();
        [CCode (cname = "osso_application_name_get")]
        public string get_application_name ();
        [CCode (cname = "osso_application_version_get")]
        public string get_application_version ();

        public Error statusbar_send_event (string name, int argument1,
                                           int argument2, string argument3,
                                           out Rpc retval);

        /* Time Notification */
        [CCode (cname = "osso_time_set_notification_cb")]
        public Error set_time_notification_callback (ref TimeCallback cb,
                                                     pointer data);
        [CCode (cname = "osso_time_set")]
        //public Error set_time (time_t new_time);

        /* Locale */
        [CCode (cname = "osso_locale_change_set_notification_cb")]
        public Error set_locale_change_notification_callback (
                ref LocaleChangeCallback cb, pointer data);
        [CCode (cname = "osso_locale_set")]
        public Error set_locale (string new_locale);

        /* System Note */
        public Error system_note_dialog (string message, SystemNoteType type,
                                         out Rpc retval);
        public Error system_note_infoprint (string text, out Rpc retval);

        /* State Saving */
        [CCode (cname = "osso_state_write")]
        public Error state_write (ref State state);
        [CCode (cname = "osso_state_read")]
        public Error state_read (out State state);

        /* Plugin */
        [CCode (cname = "osso_cp_plugin_execute")]
        public Error plugin_execute (string filename, pointer data,
                                     bool user_activated);
        [CCode (cname = "osso_cp_plugin_execute")]
        public Error plugin_save (string filename, pointer data);

        /* Device State */
        public Error display_state_on ();
        public Error display_blanking_pause ();

        [CCode (cname = "osso_hw_set_event_cb")]
        public Error set_hw_event_callback (ref HWState state,
                                            ref HWCallback cb, pointer data);
        [CCode (cname = "osso_hw_unset_event_cb")]
        public Error unset_hw_event_callback (ref HWState state, pointer data);
        [CCode (cname = "osso_hw_set_display_event_cb")]
        public Error set_hw_display_event_callback (ref DisplayEventCallback cb,
                                                    pointer data);

        /* Mime */
        [CCode (cname = "osso_mime_set_cb")]
        public Error set_mime_callback (ref MimeCallback cb, pointer data);
        [CCode (cname = "osso_mime_unset_cb")]
        public Error unset_mime_callback ();
        [CCode (cname = "osso_mime_unset_cb_full")]
        public Error unset_mime_callback_full (ref MimeCallback cb,
                                               pointer data);

        /* DBus */
        public pointer get_dbus_connection ();
        public pointer get_sys_dbus_connection ();
    }

    /* Callbacks */
    [CCode (cname = "osso_rpc_cb_f")]
    public static delegate int RpcCallback (string iface, string method,
                                            GLib.Array arguments, pointer data,
                                            out Rpc rpc);
    [CCode (cname = "osso_rpc_async_f")]
    public static delegate int RpcAsync (string iface, string method,
                                         out Rpc rpc, pointer data);
    //[CCode (cname = "osso_rpc_argfill")]
    //public static delegate void RpcArgfill (ref DBus.Message msg,
    //                                        pointer data);

    [CCode (cname = "osso_application_top_cb_f")]
    public static delegate void ApplicationTopCallback (string arguments,
                                                        pointer data);
    [CCode (cname = "osso_application_autosave_cb_f")]
    public static delegate void ApplicationAutosaveCallback (pointer data);
    [CCode (cname = "osso_time_cb_f")]
    public static delegate void TimeCallback (pointer data);
    [CCode (cname = "osso_locale_change_cb_f")]
    public static delegate void LocaleChangeCallback (string new_locale,
                                                      pointer data);
    [CCode (cname = "osso_display_event_cb_f")]
    public static delegate void DisplayEventCallback (DisplayState state,
                                                      pointer data);

    [CCode (cname = "osso_hw_cb_f")]
    public static delegate void HWCallback (ref HWState state, pointer data);

    [CCode (cname = "osso_mime_cb_f")]
    public static delegate void MimeCallback (pointer data, int argc, 
                                              char **argv);

    /* Structs */
    [CCode (cname = "osso_state_t")]
    public struct State {
        public uint32 state_size;
        public pointer state_data;
    }

    [CCode (cname = "osso_hw_state_t")]
    public struct HWState {
        public bool shutdown_ind;
        public bool save_unsaved_data_ind;
        public bool memory_low_ind;
        public bool system_inactivity_ind;
        DevMode sig_device_mode_ind;
    }

    [CCode (unref_function = "osso_rpc_free_val", cname = "osso_rpc_t")]
    public struct Rpc {
        public int type;
        public GLib.Value value;
    }
    //    int type;
    //    Value 
    //    union {
    //        uint32 u;
    //        int32 i;
    //        bool b;
    //        double d;
    //        string s;
    //    } value;
    //}

    /* Enums */
    [CCode (cname = "osso_return_t", cprefix = "OSSO_")]
    public enum Error {
        OK = 0,
        ERROR = -1,
        INVALID = -2,
        RPC_ERROR = -3,
        ERROR_NAME = -4,
        ERROR_NO_STATE = -5,
        ERROR_STATE_SIZE = -6
    }

    [CCode (cname = "osso_system_note_type_t", cprefix = "OSSO_GN_")]
    public enum SystemNoteType {
        WARNING = 0,
        ERROR,
        NOTICE,
        WAIT
    }

    [CCode (cname = "osso_devmode_t", cprefix = "OSSO_DEVMODE_")]
    public enum DevMode {
        NORMAL = 0,
        FLIGHT,
        OFFLINE,
        INVALID
    }

    [CCode (cname = "osso_display_state_t", cprefix = "OSSO_DISPLAY_")]
    public enum DisplayState {
        ON,
        OFF,
        DIMMED
    }

}
